package com.yayo.mangement.info;

import com.yayo.mangement.utils.StringUtils;
import lombok.Data;

import java.io.Serializable;

@Data
public class MenuInfo implements Serializable {

    private static final long serialVersionUID = 7726393103207215503L;
    private Long menuId;
    private String name;
    private String uri;
    private String uriPattern;

    public void setUri(String uri){
        this.uri = uri;
        if(StringUtils.isBlank(uri)){
            return ;
        }
        String[] uriArr = uri.split("/");
        this.uriPattern = "^";
        for(int i = 0; i < uriArr.length; i ++){
            if(uriArr[i].startsWith("{") && uriArr[i].endsWith("}")){
                this.uriPattern += ("/" + "([^/]*)");
            }else{
                this.uriPattern += StringUtils.isBlank(uriArr[i])?"":("/" + uriArr[i]);
            }
        }
        this.uriPattern += "$";
    }

}
